package com.lry.basic.algorithm.common;

/**
 * @author:刘仁有
 * @desc:
 * @email:953506233@qq.com
 * @data:2019/10/15
 */
public class SearchMatrix2 {
    public static void main(String[] args) {
        SearchMatrix2 m = new SearchMatrix2();
//        1,4,7
//        2,5,8
//        3,6,9
        System.out.println(m.searchMatrix(new int[][]{{1,4,7},{2,5,8},{3,6,9}},-1));
    }
    public boolean searchMatrix(int[][] matrix, int target) {
        if(null==matrix||matrix.length<=0||matrix[0].length<=0)return false;
        int i=matrix.length-1;//定位到最后一行
        int j=0;//定位第一列
        //在数组中
        while(i>=0&&j<matrix[0].length){
            if(target==matrix[i][j]){
                return true;
            }else if(target>matrix[i][j]){
                j++;
            }else{
                i--;
            }
        }
        return false;
    }
}
